#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QMimeData>
#include "romfs2.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    setAcceptDrops(true);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::dropEvent(QDropEvent *event)
{
    QList<QUrl> urls;

    urls = event->mimeData()->urls();
    if (urls.isEmpty())
       return;

    QString filename = urls.first().toLocalFile();
    romfs2 fs;

    fs.mkimg(filename);
    statusBar()->showMessage(fs.errstr, 5000);
}

void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
    //如果为文件，则支持拖放
    if (event->mimeData()->hasFormat("text/uri-list"))
        event->acceptProposedAction();
}
